"""
插件系统异常定义
提供插件级异常基类，隔离崩溃
"""

from typing import Any, Optional


class PluginError(Exception):
    """插件系统基础异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None, **kwargs: Any) -> None:
        self.message = message
        self.plugin_name = plugin_name
        self.extra = kwargs
        super().__init__(message)
    
    def __str__(self) -> str:
        if self.plugin_name:
            return f"[Plugin: {self.plugin_name}] {self.message}"
        return self.message


class PluginLoadError(PluginError):
    """插件加载失败异常"""
    pass


class PluginDependencyMissing(PluginError):
    """插件依赖缺失异常"""
    
    def __init__(self, plugin_name: str, missing_deps: list[str], **kwargs: Any) -> None:
        self.missing_deps = missing_deps
        message = f"Missing dependencies: {', '.join(missing_deps)}"
        super().__init__(message, plugin_name, **kwargs)


class PluginConfigError(PluginError):
    """插件配置错误异常"""
    pass


class PluginRuntimeError(PluginError):
    """插件运行时错误异常"""
    pass
